/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import com.sun.mail.smtp.SMTPMessage;
import java.io.UnsupportedEncodingException;
//import java.net.Authenticator;
//import java.net.PasswordAuthentication;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
/**
 *
 * @author Remco
 */
public class SendMail {
     public static void send(String to, String subject, String text) throws AddressException, MessagingException, UnsupportedEncodingException {
        final String username = "team2pdl@gmail.com";
        final String password = "team2pdl!";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Authenticator auth = new Authenticator() {

            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
               return new PasswordAuthentication(username, password);
            }
        };
        
 Session mailSession = Session.getInstance( props, auth);
        Message message = new SMTPMessage(mailSession);
        message.setFrom(new InternetAddress(username, "Dryves"));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject(subject);
        message.setText(text);

        Transport.send(message);
    }
}
